package com.qst.crop.service.impl;

import com.qst.crop.entity.Purchase;
import com.qst.crop.dao.PurchaseDao;
import com.qst.crop.entity.SellPurchase;
import com.qst.crop.model.MyPurchase;
import com.qst.crop.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

import java.util.List;


@Service
public class PurchaseServiceImpl implements PurchaseService {

    @Autowired
    private PurchaseDao purchaseDao;

    @Override
    public void add(Purchase purchase){
        purchaseDao.insertSelective(purchase);
    }
    @Override
    public Purchase selectNewPurchaseId(String ownName){
        Purchase purchase = purchaseDao.selectNewPurchaseId(ownName);
        return purchase;
    }
    @Override
    public List<MyPurchase> selectByPurchaseType(){

        UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String name = principal.getUsername();
        List<MyPurchase> purchases = purchaseDao.selectByPurchase(name);
        System.out.println(purchases);
        return purchases;
    }

}
